package tech.wangpai.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import tech.wangpai.domain.User;
import tech.wangpai.repository.UserMapper;
import tech.wangpai.service.UserService;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    public UserMapper userMapper;

    @Override
    public List<User> queryUser(String username) {
        User user = new User();
        user.setUsername(username);
        PageHelper.startPage(1,10);
        List<User> userList = userMapper.select(user);
        //PageInfo<User> pageInfo = new PageInfo<>(users);
        return userList;
    }

    @Override
    public User getUserById(String userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    @Override
    public void addUser(User user) {
        userMapper.insert(user);
    }

    @Override
    public void delUserById(String userId) {
        userMapper.deleteByPrimaryKey(userId);

    }

    @Override
    public void updateUserById(String userId, User user) {
        userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public void updateUserAgeById(String userId, Integer age) {
        User user = new User();
        user.setUserId(userId);
        user.setAge(age);
        userMapper.updateByPrimaryKeySelective(user);
    }
}
